/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author quy
 */
@Entity
@Table(name = "ProductWarehouse")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ProductWarehouse.findAll", query = "SELECT p FROM ProductWarehouse p"),
    @NamedQuery(name = "ProductWarehouse.findByProductID", query = "SELECT p FROM ProductWarehouse p WHERE p.productWarehousePK.productID = :productID"),
    @NamedQuery(name = "ProductWarehouse.findByWarehouseID", query = "SELECT p FROM ProductWarehouse p WHERE p.productWarehousePK.warehouseID = :warehouseID"),
    @NamedQuery(name = "ProductWarehouse.findByQuantity", query = "SELECT p FROM ProductWarehouse p WHERE p.quantity = :quantity")})
public class ProductWarehouse implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductWarehousePK productWarehousePK;
    @Column(name = "Quantity")
    private Integer quantity;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @JoinColumn(name = "WarehouseID", referencedColumnName = "WarehouseID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Warehouse warehouse;
    @JoinColumn(name = "ProductID", referencedColumnName = "ProductID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;

    public ProductWarehouse() {
    }

    public ProductWarehouse(ProductWarehousePK productWarehousePK) {
        this.productWarehousePK = productWarehousePK;
    }

    public ProductWarehouse(int productID, int warehouseID) {
        this.productWarehousePK = new ProductWarehousePK(productID, warehouseID);
    }

    public ProductWarehousePK getProductWarehousePK() {
        return productWarehousePK;
    }

    public void setProductWarehousePK(ProductWarehousePK productWarehousePK) {
        this.productWarehousePK = productWarehousePK;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }
    public Warehouse getWarehouse() {
        return warehouse;
    }

    public void setWarehouse(Warehouse warehouse) {
        this.warehouse = warehouse;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productWarehousePK != null ? productWarehousePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductWarehouse)) {
            return false;
        }
        ProductWarehouse other = (ProductWarehouse) object;
        if ((this.productWarehousePK == null && other.productWarehousePK != null) || (this.productWarehousePK != null && !this.productWarehousePK.equals(other.productWarehousePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.aal.entity.ProductWarehouse[ productWarehousePK=" + productWarehousePK + " ]";
    }
    
}
